using System;
using System.Xml;
using System.Collections;

namespace ScenarioFramework.WorkflowEngine.DataModel.Common
{
	//*********************************************************************
	//
	// XMLExtendedAttributes Class
	//
	// The XMLExtendedAttributes class represents a collection base of XMLExtendedAttribute
	// Its imports methods from WAPI.XmlObjectSet like get set and add
	// XMLExtendedAttributes Has no fields
	//
	//*********************************************************************

	public class XMLExtendedAttributes : bOSdotNET.XML.Data.XMLObjectSet 
	{
		public const string MAIN_NODE	= "ExtendedAttributes";

		/** FIELDS **/

		/** no fields **/

		/** CONSTRUCTORS **/

		/** CONSTRUCTOR Empty **/
		public XMLExtendedAttributes()
		{
			this.Init();
		}

		/** CONSTRUCTOR Width xml parsering**/
		public XMLExtendedAttributes(System.Xml.XmlNode nodeList)
		{
			this.Parse(nodeList);
		}

		/** INSTANCE METHODS **/

		public override void Init()
		{
			this.RemoveAll();
		}

		/**Method to parse an xml string into a nodelist collection **/

		override public void Parse(System.Xml.XmlNode nodeList)
		{
			this.Init();

			System.Xml.XmlNode node;

			for ( int i=0; i<nodeList.ChildNodes.Count;i++)
			{
				node = nodeList.ChildNodes[i];

				switch ( node.Name) 
				{
					case XMLExtendedAttribute.MAIN_NODE:
						this.Add ( new XMLExtendedAttribute(node));
						break;
				}
			}
		}

		/**Method to retive a nodelist from collection **/
		override public bOSdotNET.XML.XMLNode GetXMLNode()
		{
			bOSdotNET.XML.XMLNode xmlNode = new bOSdotNET.XML.XMLNode(XMLExtendedAttributes.MAIN_NODE);

			for ( int i=0; i<this.Count;i++)
			{
				xmlNode.AddNode ( this[i].GetXMLNode() );
			}

			return xmlNode;
		}


		/** SORTING METHODS **/

		/** Method for return a functionParameter from collection **/
		public XMLExtendedAttribute Get(string sName)
		{
			XMLExtendedAttribute parameter;

			for ( int i=0; i<this.List.Count; i++)
			{
				parameter = (XMLExtendedAttribute)this.List[i];
				if ( parameter.Name == sName )
				{
					return parameter;
				}
			}

			throw new ScenarioFramework.WorkflowEngine.DataModel.Exception.ExtendedAttributeNotFound(sName);
		}

		/** Method for return a functionParameter from collection **/
		public XMLExtendedAttribute Get(string sName, string sValue)
		{
			XMLExtendedAttribute parameter;

			for ( int i=0; i<this.List.Count; i++)
			{
				parameter = (XMLExtendedAttribute)this.List[i];
				if ( ( parameter.Name == sName ) && (parameter.Value == sValue) )
				{
					return parameter;
				}
			}

			throw new ScenarioFramework.WorkflowEngine.DataModel.Exception.ExtendedAttributeNotFound(sName);
		}
	}
}